﻿coding='utf-8'
import base64
import hashlib 
import hmac 
import json 
import time 
import logging 
import requests
import mysql.connector
import datetime
import json

crm_server = "https://capi.qumei.com/api/home/call" 
token="2c1a8e0578a93f80d9cb38fa5183fe94a6f3072320d6242d7910eb8fcc91757e"
username="webuser";
password="Qumei1993";
t=time.time()
timestamp=int(round(t))
sign =username+","+password+","+str(timestamp);
sign= hashlib.md5(sign.encode())
sign=sign.hexdigest()
headers = {"Content-Type":"application/json","Authorization":"Bearer "+token,"username":username,"password":password,"timestamp":str(timestamp),"sign":sign}
print(headers)
headers = requests.get(url = 'http://od.qumei.com/cc/api.php?type=1').text
header = json.loads(headers.encode())

header['Authorization'] ='Bearer ' + header['Authorization']

print(header)

CusName = '测试'
CusAddress = '北京'
data = {'CusName': CusName,'CusPhone': '18801263885','ChannelID':'1262592253055078400','CusAddress':CusAddress,'Remark':''}

pp={"Service":"com.QM.CallCenter.CommonChannelAPI","Param":data} #json.dumps(data,ensure_ascii=False)

ppi=json.dumps(pp)

# # ppi=ppi.replace('\\','')

print(pp)

r = requests.post(url=crm_server, data=pp,headers=header) #

print(r.text)